package src.dual_pointers;

import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Set;

/**
 * @author starsea
 * @date 2024-07-30 22:15
 */

public class test01 {
    public static void main(String[] args) {
        System.out.println(isHappy(19));

    }
    public static boolean isHappy(int n) {
        Set<Integer> set = new HashSet<>();
        while (n != 1) {

            if (set.contains(n)) {
                return false;
            }
            set.add(n);
            n = ways(n);

        }
        return true;
    }

    public static int ways(int n) {
        int sum = 0;
        while (n != 0) {
            int pos = n % 10;
            sum += Math.pow(n,2);
            n/=10;
        }
        return sum;
    }
}